package cn.zyq.baking.controller;

import cn.zyq.baking.commons.response.JsonResult;
import cn.zyq.baking.pojo.vo.CategoryVO;
import cn.zyq.baking.service.ICategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;

@RestController
@RequestMapping("/categories")
public class CategoryController {

    @Autowired
    ICategoryService categoryService;

    @GetMapping("/type-list")
    public JsonResult typeList(){
        List<CategoryVO> typeList=categoryService.typeList();
        return JsonResult.ok(typeList);
    }

    @GetMapping("/{id}/sub")
    public JsonResult getSubTypeByTypeId(@PathVariable Long id){
        List<CategoryVO> subTypeList= categoryService.subListByType(id);
        return JsonResult.ok(subTypeList);
    }

}